//
//  LOLBaseModel.m
//  LOLXXbox
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLBaseModel.h"

@implementation LOLBaseModel
+(NSMutableArray *)baseModelByArr:(NSArray *)arr
{
    //创建一个数组,用来装model
    NSMutableArray *modelArr=[NSMutableArray array];
    //对数组进行遍历,里面的元素都是字典
    
    for (NSDictionary *dic in arr) {
        //通过便利构造器的方式创建对象
        @autoreleasepool {
            
            id model= [[self class] baseModelWithDic:dic];
            [modelArr addObject:model];
        }
    }
    
    return modelArr;
    
    
}

#pragma mark 便利构造器方法用来创建对象
+(instancetype)baseModelWithDic:(NSDictionary *)dic
{
    //采用多态的方式进行对象的创建
    id model = [[[self class] alloc ]initWithDic:dic];
    return model;
    
    
}

#pragma mark 自定义初始化方法用来实现对model用KVC进行赋值
-(instancetype)initWithDic:(NSDictionary *)dic
{
    self=[super init];
    if (self) {
        //用KVC的方式对成员变量进行赋值
        
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
    
    
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"id"]) {
        self.typeId=value;
    }
    if ([key isEqualToString:@"description"]) {
        self.descriptions=value;
    }
    
    
}

@end
